<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>

<script runat="server" language="c#">

private string strResult = "";

void btnGo_Click(object sender, EventArgs e)
{
   HttpWebRequest myReq = CreateRequest(rblDevices.SelectedIndex);
   WebResponse myRes = myReq.GetResponse();
   Stream myStream = myRes.GetResponseStream();
   strResult = "";
   String strNext;
   int iNext;
   char cNext;
   do
   {
      iNext = myStream.ReadByte();
      if (iNext != -1)
      {
         cNext = (char)iNext;
         strNext = cNext.ToString();
         strResult += strNext;
      }
   }
   while (iNext != -1);
   myStream.Close();
   tbResult.Text = strResult;
}

HttpWebRequest CreateRequest(int DeviceType)
{
   HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(txtURL.Text);
   switch (DeviceType)
   {
   case 0:
      lblDevice.Text = ", using IE";
      break;
   case 1:
      lblDevice.Text = ", using Pocket PC";
      myReq.Accept = "*/*";
      myReq.UserAgent = "Mozilla/2.0(compatible; MSIE 3.02; Windows CE; 240x320)";
      break;
   case 2:
      lblDevice.Text = ", using Nokia 7110";
      myReq.Accept = "application/vnd.wap.wtls-ca-certificate, application/vnd.wap.wmlscriptc, application/vnd.wap.wmlc, image/vnd.wap.wbmp, text/plain, text/vnd.wap.wmlscript, text/html, text/vnd.wap.wml";
      myReq.UserAgent = "Nokia7110/1.0 (04.80)";
      break;
   case 3:
      lblDevice.Text = ", using Phone.com UP.Browser 4.0";
      myReq.Accept = "application/x-hdmlc, application/x-up-alert, application/x-up-cacheop, application/x-up-device, application/x-up-digestentry, application/vnd.wap.wml, text/x-wap.wml, text/vnd.wap.wml, application/vnd.wap.wmlscript, text/vnd.wap.wmlscript, application/vnd.uplanet.channel, application/vnd.uplanet.list, text/x-hdml, text/plain, text/html, image/vnd.wap.wbmp, image/bmp, application/remote-printing text/x-hdml;version=3.1, text/x-hdml;version=3.0, text/x-hdml;version=2.0, image/bmp, text/html";
      myReq.UserAgent = "UPG1 UP/4.0.10 UP.Browser/4.0.10-XXXX UP.Link/4.1.HTTP-DIRECT";
      break;
   case 4:
      lblDevice.Text = ", using Openwave UP.Browser 4.1";
      myReq.Accept = "application/x-hdmlc, application/x-up-alert, application/x-up-cacheop, application/x-up-device, application/x-up-digestentry, application/vnd.wap.wml, text/x-wap.wml, text/vnd.wap.wml, application/vnd.wap.wmlscript, text/vnd.wap.wmlscript, application/vnd.uplanet.channel, application/vnd.uplanet.list, text/x-hdml, text/plain, image/vnd.wap.wbmp, image/bmp, application/remote-printing text/x-hdml;version=3.1, text/x-hdml;version=3.0, text/x-hdml;version=2.0, image/bmp, text/html";
      myReq.UserAgent = "OWG1 UP/4.1.20a UP.Browser/4.1.20a-XXXX UP.Link/4.1.HTTP-DIRECT";
      myReq.Headers.Add("X_UP_DEVCAP_NUMSOFTKEYS", "2");
      break;
   case 5:
      lblDevice.Text = ", using Benefon Q with MME";
      myReq.Accept = "image/gif , text/html , image/jpeg , text/vcal , text/vcard , image/vnd.wap.wbmp , application/vnd.wap.wmlc , application/vnd.wap.wmlscriptc , */*";
      myReq.UserAgent = "Mozilla/1.22 (compatible; MMEF20; CellPhone)";
      break;
   case 6:
      lblDevice.Text = ", using Motorola MADK Simulator";
      myReq.Accept = "text/x-vxml, */*";
      myReq.UserAgent = "Motorola VoxGateway/2.0";
      break;
   case 7:
      lblDevice.Text = ", using Ericsson R320 Simulator";
      myReq.Accept = "text/vnd.wap.wml, application/vnd.wap.wmlc, application/vnd.wap.wmlscriptc, application/vnd.wap.wbxml, image/vnd.wap.wbmp, image/xbm, image/gif, image/jpeg";
      myReq.UserAgent = "WapIDE-SDK/2.1; (R320s (Arial))";
      break;
   case 8:
      lblDevice.Text = ", using Ericsson R380 Simulator";
      myReq.Accept = "application/vnd.wap.wmlc, application/vnd.wap.wbxml, application/vnd.wap.wmlscriptc, */*,text/vnd.wap.wmlscript,text/html,text/plain,text/vnd.wap.wml";
      myReq.UserAgent = "R380 2.0 WAP1.1";
      break;
   }
   return myReq;
}

</script>

<html>
<head>
<title>Client Impersonator</title>
</head>
<body>
<form runat=server>
Select device to impersonate:<br/>
<asp:RadioButtonList runat=server id="rblDevices">
   <asp:ListItem selected=true>Internet Explorer</asp:ListItem>
   <asp:ListItem>Pocket PC</asp:ListItem>
   <asp:ListItem>Nokia 7110</asp:ListItem>
   <asp:ListItem>Phone.com UP.Browser 4.0</asp:ListItem>
   <asp:ListItem>Openwave UP.Browser 4.1</asp:ListItem>
   <asp:ListItem>Benofon Q with MME</asp:ListItem>
   <asp:ListItem>Motorola MADK</asp:ListItem>
   <asp:ListItem>Ericsson R320 Simulator</asp:ListItem>
   <asp:ListItem>Ericsson R380 Simulator</asp:ListItem>
</asp:RadioButtonList><br/>
Select URL to load:<br/>
<asp:TextBox runat=server id="txtURL" Text="http://localhost/MC/Example1.aspx" columns="100"/><br/><br/>
<asp:Button runat=server id="btnGo" OnClick="btnGo_Click" Text="Get result"/><br/><br/>
</form>
Results<asp:Label runat=server id="lblDevice"/>:<br/>
<asp:TextBox runat=server rows=50 columns="100" textmode="multiline" enabled="false" id="tbResult"/>

</body>
</html>

